Skip to content

Conversation

@danal-odoo
Copy link

@danal-odoo danal-odoo commented Dec 19, 2025

Before, the product selection dropdown did not display the
time of the previous order and products were not sorted based on how
recently they were invoiced for the selected customer. Additionally,
the last invoice time and specific quantity calculations were missing
from the catalog view.

This module enhances the product selection mechanism to assist users in
identifying frequently purchased items. Specific improvements include:

  • Displaying the last_order time next to the product name in the
    dropdown.
  • Sorting products by last_invoice_date specific to the selected
    customer (partner).
  • Showing final_qty and last_invoice_time in the product
    catalog kanban view.

If no customer is selected in the context, the standard selection
behavior and sorting apply.

Technical Details:

  • Model product.product: Added last_order Datetime field,
    last_invoice_date Datetime Field, last_invoice_time field.

  • Model product.template: Added last_order Datetime field,
    last_invoice_date Datetime Field.

  • Method name_search: Overridden to order products as last_invoice_date.

  • Method _compute_display_name: Overridden to show last_order as to string
    time at right side of product name in selection dropdown.

  • Method _compute_last_order: to compute last_order of shown products in
    selection dropdown in context of selected customer(partner_id).

  • Method _compute_last_invoice_date: to compute last_invoice_date to order
    recently invoiced first shown products in selection dropdown in context of
    selected customer(partner_id).

  • Method compute_agotime: to compute given Datetime to string format.

  • View sale_order_views: Updated product_template_id and catalog button
    to pass the selected partner_id in the context as customer.

  • View account_move_views: Updated product_id and catalog button
    to pass the selected partner_id in the context as customer.

  • View purchase_order_views: Updated product_id to pass the selected
    partner_id in the context as vendor.

  • View product_views: Updated product_view_kanban_catalog to display
    final_qty (virtual_available - qty_available) next to On Hand and
    last_invoice_time after qty_available in product_view_kanban_catalog.

  • Template order_line: Updated to show uomDisplayName next to price.

@robodoo
Copy link

robodoo commented Dec 19, 2025

Pull request status dashboard

@danal-odoo danal-odoo force-pushed the 19.0-last_purchased_products-danal branch from 67e219c to 3a32fc9 Compare December 19, 2025 06:28
@danal-odoo danal-odoo changed the title [ADD] last_purchased_products: last order time in product dropdown [ADD] last_purchased_products: sort selection by recent customer history Dec 19, 2025
@danal-odoo danal-odoo force-pushed the 19.0-last_purchased_products-danal branch 3 times, most recently from b81855c to 3b80222 Compare December 22, 2025 09:20
Before, the product selection dropdown did not display the
time of the previous order and products were not sorted based on how
recently they were invoiced for the selected customer. Additionally,
the last invoice time and specific quantity calculations were missing
from the catalog view.

This module enhances the product selection mechanism to assist users in
identifying frequently purchased items. Specific improvements include:
- Displaying the `last_order` time next to the product name in the
  dropdown.
- Sorting products by `last_invoice_date` specific to the selected
  customer (partner).
- Showing `final_qty` and `last_invoice_time` in the product
  catalog kanban view.

If no customer is selected in the context, the standard selection
behavior and sorting apply.

Technical Details:
- Model `product.product`: Added `last_order` Datetime field,
   `last_invoice_date` Datetime Field, `last_invoice_time` field.
- Model `product.template`: Added `last_order` Datetime field,
   `last_invoice_date` Datetime Field.
- Method `name_search`: Overridden to order products as `last_invoice_date`.
- Method `_compute_display_name`: Overridden to show `last_order` as to string
   time at right side of product name in selection dropdown.
- Method `_compute_last_order`: to compute `last_order` of shown products in
   selection dropdown in context of selected customer(`partner_id`).
- Method `_compute_last_invoice_date`: to compute `last_invoice_date` to order
   recently invoiced first shown products in selection dropdown in context of
   selected customer(`partner_id`).
- Method `compute_agotime`: to compute given Datetime to string format.

- View `sale_order_views`: Updated `product_template_id` and catalog button
   to pass the selected `partner_id` in the context as `customer`.
- View `account_move_views`: Updated `product_id` and catalog button
   to pass the selected `partner_id` in the context as `customer`.
- View `purchase_order_views`: Updated `product_id` to pass the selected
  `partner_id` in the context as `vendor`.
- View `product_views`: Updated `product_view_kanban_catalog` to display
  `final_qty` (`virtual_available` - `qty_available`) next to `On Hand` and
  `last_invoice_time` after `qty_available` in `product_view_kanban_catalog`.

- Template `order_line`: Updated to show `uomDisplayName` next to `price`.
@danal-odoo danal-odoo force-pushed the 19.0-last_purchased_products-danal branch from 3b80222 to c8e3426 Compare December 22, 2025 12:11
…ting logic

This commit introduces the `TestLastOrderProduct` test suite to ensure the
stability of product sorting and time computation based on sales and
purchase history.

Key scenarios covered:

Last Order Computation:
   - Verifies that confirming a Sale Order updates the `last_order` field.
   - Checks that the 'Ago' time suffix (e.g., '--1h--') is correctly
     appended to `display_name` when the context is active.

Last Invoice Date:
   - Verifies that posting a Customer Invoice updates `last_invoice_date`.
   - Ensures valid date comparisons between fields.

Vendor Bill Sorting:
   - Verifies that posting a Vendor Bill updates `last_invoice_date`
     when in a vendor context.
   - Ensures products from recent bills appear at the top of search results.

Name Search Sorting:
   - Verifies that recently invoiced products appear at the top of the
     list in the `name_search` results.
   - Confirms that sorting falls back to the default (alphabetical)
     when no customer/vendor context is provided.

Time Display Logic:
   - Validates `last_invoice_time` computation.
   - Specifically verifies that invoices created less than a minute ago
     return 'Just Now'.

Context Handling:
   - Ensures logic only triggers when `customer`, `vendor`, or
     `formatted_display_name` keys are present in the context, preventing
     unwanted side effects in standard views.
@danal-odoo danal-odoo force-pushed the 19.0-last_purchased_products-danal branch from c8e3426 to 6ae505d Compare December 22, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants